<template>
	<el-container class="home-container">
		<!-- 头部区域 -->
		<el-header class="header">
			<div>
				<img src="../assets/meeting.png" alt />
				<span style="font-size:34px;margin-left:5px;">会议室预约系统</span>
			</div>
			<div class="header-right">
			    <div class="header-user-con">
			        <!-- 全屏显示 -->
			        <div class="btn-fullscreen" @click="handleFullScreen">
			            <el-tooltip effect="dark" :content="fullscreen?`取消全屏`:`全屏`" placement="bottom">
			                <i class="el-icon-rank"></i>
			            </el-tooltip>
			        </div>
			        <!-- 消息中心 -->
			        <div class="btn-bell">
			            <!-- <el-tooltip
			                effect="dark"
			                :content="message?`有${message}条未读消息`:`消息中心`"
			                placement="bottom"
			            > -->
						<el-tooltip
						    effect="dark"
						    :content="message?`有${1}条未读消息`:`消息中心`"
						    placement="bottom">
			                <router-link to="/login">
			                    <i class="el-icon-bell"></i>
			                </router-link>
			            </el-tooltip>
			            <span class="btn-bell-badge" v-if="message"></span>
			        </div>
			        <!-- 用户头像 -->
			        <div class="user-avator">
			            <img :src="userInfo.staffImge" />
			        </div>
			        <!-- 用户名下拉菜单 -->
			        <el-dropdown class="user-name" trigger="click" @command="handleCommand">
			            <span class="el-dropdown-link">
			                {{userInfo.staffName}}
			                <i class="el-icon-caret-bottom"></i>
			            </span>
			            <el-dropdown-menu slot="dropdown">
							<el-dropdown-item divided command="lookSelf">个人中心</el-dropdown-item>
			                <!-- <a href="https://github.com/lin-xin/vue-manage-system" target="_blank">
			                    <el-dropdown-item>个人中心</el-dropdown-item>
			                </a> -->
			                <el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
			            </el-dropdown-menu>
			        </el-dropdown>
			    </div>
			</div>
			<!-- <el-button type="info" @click="logout">退出</el-button> -->
		</el-header>
		<!-- 页面主体区域 -->
		<el-container>
			<!-- 侧边栏 -->
			<el-aside :width="isCollapse ? '64px' : '240px'">
				<div class="toggle-button" @click="toggleCollapse">|||</div>
				<!-- 侧边栏菜单区域 -->
				<el-menu :default-active="activePath" :router="true" :collapse-transition="false" :collapse="isCollapse"
				 :unique-opened="true" background-color="#333744" text-color="#fff" active-text-color="#409eff" >
					<!-- 一级菜单 -->
					<el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
						<!-- 一级菜单的模板 -->
						<template slot="title">
							<!-- 图标 -->
							<i :class="iconsObj[item.id]" style="font-size:22px;"></i>
							<!-- 文本 -->
							<span style="font-size:22px">{{ item.authName }}</span>
						</template>
						<!-- 二级菜单 -->
						<el-menu-item  @click="saveNavState('/' + subItem.path)" :index="'/' + subItem.path" v-for="subItem in item.children"
						 :key="subItem.id">
							<template slot="title">
								<!-- 图标 -->
								<i :class="iconsObj[subItem.id]"></i>
								<!-- 文本 -->
								<span style="font-size:18px">{{ subItem.authName }}</span>
							</template>
						</el-menu-item>
					</el-submenu>
				</el-menu>
			</el-aside>
			<!-- 右侧内容 -->
			<el-main>
				<!-- 路由占位符 -->
				<router-view></router-view>
			</el-main>
		</el-container>
	</el-container>
</template>

<script>
	import bus from './bus.js';
	export default {
		data() {
			return {

				userInfo:JSON.parse(localStorage.getItem("userInfo")),
				collapse: false,
				fullscreen: false,
				name: 'linxin',
				message: 2,
				// 左侧菜单数据
				menulist: [{
						id: 101,
						authName: '申请会议',
						path: 'null',
						children: [{
								id: 1011,
								authName: '进行预约',
								path: 'book'
							},
							{
								id: 1012,
								authName: '取消预约',
								path: 'cancelBook'
							}
						]
					},
					{
						id: 102,
						authName: '预约进程',
						path: 'null',
						children: [{
								id: 1021,
								authName: '已通过',
								path: 'approved'
							},
							{
								id: 1022,
								authName: '未通过',
								path: 'notApproved'
							},
							{
								id: 1023,
								authName: '审核中',
								path: 'approving'
							}
						]
					},
					{
						id: 103,
						authName: '我的会议',
						path: 'notApproved',
						children:[{
							id:103,
							authName:'今日会议',
							path: 'TodayMeeting'
						}]
					},
					{
						id: 104,
						authName: '历史会议',
						path: 'null',
						children: [{
								id: 1041,
								authName: '我的预约',
								path: 'HistoryApply'
							},
							{
								id: 1042,
								authName: '我的参与',
								path: 'history'
							}
						]
					},
					{
						id: 105,
						authName: '个人中心',
						path: 'null',
						children: [{
								id: 1051,
								authName: '我的信息',
								path: 'myInformation'
							},
							{
								id: 1052,
								authName: '账号与安全',
								path: 'myAccount'
							}
						]
					}
				],
				iconsObj: {
					101: 'iconfont icon-baobiao',
					102: 'iconfont icon-users',
					1011: 'el-icon-circle-plus',
					1012: 'el-icon-error',
					1021: 'el-icon-folder-checked',
					1022: 'el-icon-folder-opened',
					1023: 'el-icon-loading',
					1024: 'el-icon-document-copy',
					103: 'el-icon-chat-round',
					104: 'el-icon-chat-line-round',
					1041: 'el-icon-thumb',
					1042: 'el-icon-position',
					105: 'el-icon-s-custom',
					1051: 'el-icon-user',
					1052: 'el-icon-setting'
				},
				isCollapse: false,
				activePath: ''
			}
		},
		created() {
			this.activePath = window.sessionStorage.getItem('activePath')
		},
		methods: {
			// 用户名下拉菜单选择事件
			async handleCommand (command) {
				if (command === 'loginout') {
					
					const { data: res } = await this.$http.get('/loginout')
						if (res.code !== 100) {
							return this.$message.error('登出失败')
						}else{
							localStorage.removeItem('userInfo');
							this.$router.push('/login');
							return this.$message.error('已注销!!!')
						}
	
				} else if (command === 'lookSelf') {
					this.$router.push('/myInformation');
				}
			},
			// 侧边栏折叠
			collapseChage () {
				this.collapse = !this.collapse;
				bus.$emit('collapse', this.collapse);
			},
			// 全屏事件
			handleFullScreen () {
				const element = document.documentElement;
				if (this.fullscreen) {
					if (document.exitFullscreen) {
						document.exitFullscreen();
					} else if (document.webkitCancelFullScreen) {
						document.webkitCancelFullScreen();
					} else if (document.mozCancelFullScreen) {
						document.mozCancelFullScreen();
					} else if (document.msExitFullscreen) {
						document.msExitFullscreen();
					}
				} else {
					if (element.requestFullscreen) {
						element.requestFullscreen();
					} else if (element.webkitRequestFullScreen) {
						element.webkitRequestFullScreen();
					} else if (element.mozRequestFullScreen) {
						element.mozRequestFullScreen();
					} else if (element.msRequestFullscreen) {
						// IE11
						element.msRequestFullscreen();
					}
				}
				this.fullscreen = !this.fullscreen;
			},

			logout() {
				window.sessionStorage.clear()
				this.$router.push('/login')
			},
			// 点击按钮,切换菜单的折叠与展开
			toggleCollapse() {
				this.isCollapse = !this.isCollapse
			},
			// 保存链接的激活状态
			saveNavState(activePath) {
				window.sessionStorage.setItem('activePath', activePath)
				this.activePath = activePath
			}
		}
	}
</script>

<style lang="less" scoped>
	.home-container {
		height: 100%;
	}

	.el-header {
		background-color: #373d41;
		display: flex;
		justify-content: space-between;
		padding-left: 0;
		align-items: center;
		color: #fff;
		font-size: 40px;

		>div {
			display: flex;
			align-items: center;
			height: 100%;

			img {
				height: 100%;
			}

			span {
				margin-left: 15px;
			}
		}
	}

	.el-menu {
		border-right: 0;
		font-size: 30px;
	}

	.el-aside {
		background-color: #333744;

		.toggle-button {
			background-color: #4a5064;
			cursor: pointer;
			color: #fff;
			font-size: 10px;
			line-height: 24px;
			text-align: center;
			letter-spacing: .2em;
		}

		.el-main {
			border-right: 0;
		}
	}

	.iconfont {
		margin-right: 10px;
	}

	.header {
		position: relative;
		box-sizing: border-box;
		width: 100%;
		font-size: 30px;
		color: #fff;
		height:80px ! important;
	}

	.collapse-btn {
		float: left;
		padding: 0 21px;
		cursor: pointer;
		line-height: 70px;
	}

	.header .logo {
		float: left;
		width: 250px;
		line-height: 70px;
	}

	/* .header.test{
    margin-left: 20px;
}
.header.test img {
    display: flex;
    width: 40px;
    height: 40px;
    border-radius: 50%;
} */
	.header-right {
		float: right;
		padding-right: 50px;
	}

	.header-user-con {
		display: flex;
		height: 70px;
		align-items: center;
	}

	.btn-fullscreen {
		display: flex;
		transform: rotate(45deg);
		margin-right: 5px;
		//调整全部大小图标
		font-size: 34px;
	}

	.btn-bell,
	.btn-fullscreen {
		display: flex;
		position: relative;
		width: 30px;
		height: 30px;
		text-align: center;
		border-radius: 15px;
		cursor: pointer;
	}

	.btn-bell-badge {
		position: absolute;
		right: 0;
		top: -2px;
		width: 8px;
		height: 8px;
		border-radius: 4px;
		background: #f56c6c;
		color: #fff;
	}

	.btn-bell .el-icon-bell {
		color: #fff;
	}

	.user-name {
		margin-left: 10px;
	}

	.user-avator {
		margin-left: 20px;
	}

	.user-avator img {
		display: block;
		width: 50px;
		height: 50px;
		border-radius: 50%;
	}

	.el-dropdown-link {
		color: #fff;
		cursor: pointer;
	}

	.el-dropdown-menu__item {
		text-align: center;
	}
</style>
